//Andrew Blowe
//Richard Garcia
//Ryan Huffman
//Craig Rowe
// Oct. 18, 2011


import java.io.*;
import java.util.*;
import java.util.ArrayList;

public class textCalc
{
	public static void main(String[]args) throws java.io.IOException
	{

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
				
		String strInput;
		int counter=0, howManyTokens;
		double dblResult;
		ArrayList<String> operatorsList = new ArrayList<String>();//array lists to put number or operator tokens in
		ArrayList<Integer> numbersList = new ArrayList<Integer>();
		ArrayList<Integer> tempNums = new ArrayList<Integer>();
		
		System.out.print("Enter numbers to calculate(separate by spaces and use whole numbers): ");
		strInput = reader.readLine();
		StringTokenizer strToken = new StringTokenizer(strInput, " ");//make list of tokens from the input
		howManyTokens=(strToken.countTokens()-1)/2;
		boolean done1=false;//get out of loops if this is true
		
		//fill up array lists
		while(strToken.hasMoreTokens())//populate lists with respective type of tokens
		{
			int intInput;
			String nxtToken = strToken.nextToken();
			if(!nxtToken.equals("+")&&!nxtToken.equals("-")&& !nxtToken.equals("*")&&!nxtToken.equals("/"))
			{
				intInput=Integer.parseInt(nxtToken);
				numbersList.add(intInput);
				
			}
			else
			{
				operatorsList.add(nxtToken);
			}
			
			
		}
		
		
		
		//do first round of calculations, mostly take care of multiplication and division or addition and subtraction if possible
		
		counter=0;
		while((counter+1)<=operatorsList.size() && !done1)
		{
			
			int tempResult=0;
			
				if(operatorsList.get(counter).equals("*"))//check for multiplication
				{
					
					
					if(operatorsList.size()<2)
					{
						tempResult=(int)numbersList.get(counter) * (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult);
						counter--;
						done1=true;
					}
					else
					{
						tempResult=(int)numbersList.get(counter) * (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult);
						counter--;	
					}
						
					
					
				}
				else if(operatorsList.get(counter).equals("/"))//division
				{
					if(operatorsList.size()<2)
					{
						tempResult=(int)numbersList.get(counter) / (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult);
						counter--;
						done1=true;
					}
					else
					{
						tempResult=(int)numbersList.get(counter) / (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult);
						counter--;
					}
					
				}
				else if(operatorsList.get(counter).equals("+"))//addition
				{
					
					if(counter==0)
					{
						if(operatorsList.size()<2)//when the list gets down to zero elements you must terminate the loop
						{
							tempResult=(int)numbersList.get(counter)+(int)numbersList.get(counter+1);
							operatorsList.remove(counter);
							numbersList.remove(counter+1);
							numbersList.set(counter, tempResult);
							counter--;
							done1=true;
						}
						else
						{
							if(!operatorsList.get(counter+1).equals("*")&&!operatorsList.get(counter+1).equals("/"))
							{
								tempResult=(int)numbersList.get(counter)+(int)numbersList.get(counter+1);
								operatorsList.remove(counter);
								numbersList.remove(counter+1);
								numbersList.set(counter, tempResult);
								counter--;
							}
						}
					}
					else if((counter+1)==howManyTokens)
					{
						if(!operatorsList.get(counter-1).equals("*")&&!operatorsList.get(counter-1).equals("/"))
						{
							tempResult=(int)numbersList.get(counter)+(int)numbersList.get(counter+1);
							operatorsList.remove(counter);
							numbersList.remove(counter+1);
							numbersList.set(counter, tempResult);
							counter--;
						}
					}
					else
					{
						if(!operatorsList.get(counter-1).equals("*") && !operatorsList.get(counter-1).equals("/")&& !operatorsList.get(counter+1).equals("*")&&!operatorsList.get(counter+1).equals("/"))
						{
							tempResult=(int)numbersList.get(counter)+(int)numbersList.get(counter+1);
							operatorsList.remove(counter);
							numbersList.remove(counter+1);
							numbersList.set(counter, tempResult);
							counter--;
						}
						
					}
				}
				else if(operatorsList.get(counter).equals("-"))//subtraction
				{
					if(counter==0)
					{
						if(operatorsList.size()<2)
						{
							tempResult=(int)numbersList.get(counter)-(int)numbersList.get(counter+1);
							operatorsList.remove(counter);
							numbersList.remove(counter+1);
							numbersList.set(counter, tempResult);
							counter--;
							done1=true;
						}
						else
						{
							if(!operatorsList.get(counter+1).equals("*")&&!operatorsList.get(counter+1).equals("/"))
							{
								tempResult=(int)numbersList.get(counter)-(int)numbersList.get(counter+1);
								operatorsList.remove(counter);
								numbersList.remove(counter+1);
								numbersList.set(counter, tempResult);
								counter--;
							}
						}
					}
					else if((counter+1)==howManyTokens)
					{
						if(!operatorsList.get(counter-1).equals("*")&&!operatorsList.get(counter-1).equals("/"))
						{
							tempResult=(int)numbersList.get(counter)-(int)numbersList.get(counter+1);
							operatorsList.remove(counter);
							numbersList.remove(counter+1);
							numbersList.set(counter, tempResult);
							counter--;
						}
					}
					else
					{
						if(!operatorsList.get(counter-1).equals("*") && !operatorsList.get(counter-1).equals("/")&& !operatorsList.get(counter+1).equals("*")&&!operatorsList.get(counter+1).equals("/"))
						{
							tempResult=(int)numbersList.get(counter)-(int)numbersList.get(counter+1);
							operatorsList.remove(counter);
							numbersList.remove(counter+1);
							numbersList.set(counter, tempResult);
							counter--;
						}
					}
				}
			
			
			
			
			
			counter++;
		
		}
		//multiplication and division are taken care of, now do the rest of the addition and subtraction
		counter=0;
		done1=false;
		
		while((counter+1)<=operatorsList.size()&& !done1)
		{
			int tempResult2=0;
			if(operatorsList.get(counter).equals("+"))
			{
					if(operatorsList.size()<2)
					{
						tempResult2=(int)numbersList.get(counter) + (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult2);
						counter--;
						done1=true;
					}
					else
					{
						tempResult2=(int)numbersList.get(counter) + (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult2);
						counter--;	
					}
				
				
			}
			else if(operatorsList.get(counter).equals("-"))
			{
				if(operatorsList.size()<2)
					{
						tempResult2=(int)numbersList.get(counter) - (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult2);
						counter--;
						done1=true;
					}
					else
					{
						tempResult2=(int)numbersList.get(counter) - (int)numbersList.get(counter+1);
						operatorsList.remove(counter);
						numbersList.remove(counter+1);
						numbersList.set(counter, tempResult2);
						counter--;	
					}
			}
			
			
			
			
			counter++;
			
		}
		
		System.out.println("\nYour result: "+numbersList); //print the number list which should be down to only one number-the result
		
		
	}
}